package com.hwadee.caixiang.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hwadee.caixiang.entity.User;
import com.hwadee.caixiang.service.ForgotPwdService;

@Controller
public class EmailController {
	@Autowired
	private ForgotPwdService forgotPwdservice;
	
	@GetMapping("/checkEmailCode")
	public @ResponseBody int checkEmailCode(String code,String emailCode) {
		int a=2;
		if(code.equals(emailCode))
		{	
			int result=1;
			return result;
		}
		else
			return a;
	}
	@RequestMapping(value = "/emails", method = RequestMethod.POST)	
	protected String doGet(String username,String email,HttpServletRequest request,HttpServletResponse response) {
//		model.
//	    // TODO Auto-generated method stub
//		System.out.println("直接运行到这儿了");
		User user = forgotPwdservice.forgot(username,email);
		String pwd = user.getPassword();
		System.out.println("密码："+pwd);
		request.setAttribute("password", pwd);	
		try {
			request.getRequestDispatcher("/foundPwd.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect:/foundPwd.jsp";
	}
}
